﻿using System;
using System.Runtime.InteropServices;//调用外部库，需要引用命名空间

/// <summary>
/// 为了调用外部库脚本
/// </summary>
public class ChinarMessage
{
    [DllImport("User32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Unicode)]
    //第一个固定参数,第二个,类容说明,第三个,题头说明,第四个,弹窗类型
    public static extern int MessageBox(IntPtr handle, String message, String title, int type);//具体方法
}

public partial class debug
{
    private static int returnNumber;

    public static int MessageBox(string message, string title = "提示")
    {
        int returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, message, title, 0);
        return returnNumber;
    }
    public static void MessageBoxButton(int index, string message, string title = "提示", params Action[] action)
    {
        switch (index)
        {
            case 0:
                returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, message, title, 0);
                action[0].Invoke();
                break;

            case 1:
                returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, message, title, 1);
                if (returnNumber == 1)
                {
                    action[0].Invoke();
                }
                else if (returnNumber == 2)
                {
                    action[1].Invoke(); 
                } 
                break;

            case 2:
                returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, message, title, 2);
                if (returnNumber == 1)
                {
                    action[0].Invoke();
                }
                else if (returnNumber == 2)
                {
                    action[1].Invoke();
                }
                else if (returnNumber == 3)
                {
                    action[1].Invoke();
                }
                break;

            case 3:
                returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, message, title, 3);
                if (returnNumber == 1)
                {
                    action[0].Invoke();
                }
                else if (returnNumber == 2)
                {
                    action[1].Invoke();
                }
                else if (returnNumber == 3)
                {
                    action[1].Invoke();
                }
                break;

            case 4:
                returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, message, title, 4);
                if (returnNumber == 1)
                {
                    action[0].Invoke();
                }
                else if (returnNumber == 2)
                {
                    action[1].Invoke();
                }
                break;

            case 5:
                returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, message, title, 5);
                if (returnNumber == 1)
                {
                    action[0].Invoke();
                }
                else if (returnNumber == 2)
                {
                    action[1].Invoke();
                }
                break;

            case 6:
                returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, message, title, 6);
                if (returnNumber == 1)
                {
                    action[0].Invoke();
                }
                else if (returnNumber == 2)
                {
                    action[1].Invoke();
                }
                else if (returnNumber == 3)
                {
                    action[1].Invoke();
                }
                break;
        }
    }
    private void MessageBoxButtons(int index)
    {
        switch (index)
        {
            case 0:
                returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, "Chinar-0:返回值均：1", "确认", 0);

                break;

            case 1:
                returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, "Chinar-1:确认：1，取消：2", "确认|取消", 1);

                break;

            case 2:
                returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, "Chinar-2:中止：3，重试：4，忽略：5", "中止|重试|忽略", 2);

                break;

            case 3:
                returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, "Chinar-3:是：6，否：7，取消：2", "是 | 否 | 取消", 3);

                break;

            case 4:
                returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, "Chinar-4:是：6，否：7", "是 | 否", 4);

                break;

            case 5:
                returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, "Chinar-5:重试：4，取消：2", "重试 | 取消", 5);

                break;

            case 6:
                returnNumber = ChinarMessage.MessageBox(IntPtr.Zero, "Chinar-6:取消：2，重试：10，继续：11", "取消 | 重试 | 继续", 6);

                break;
        }
    }
}